<script setup>
import {ref} from "vue";
import request9191 from "../../../utils/request9191.js";
import {ElMessage, ElMessageBox} from "element-plus";
import {Delete} from "@element-plus/icons-vue";
//自己社团的活动申请
const MyActivity = ref()

const getMyActivity = () =>{
  if(sessionStorage.getItem("name") === null){
    ElMessage.error("请先登录")
    return
  }
  request9191({
    url: '/ClubActReg/getByActClub',
    method: 'get',
    params:{
      actClub:sessionStorage.getItem("club")
    }
  }).then((res) =>{
    MyActivity.value=res.data.data
  })
}
getMyActivity()

//更新状态
const updateModStatus = (status , id) =>{
  request9191({
    url: '/ClubActReg/ActivityModStatus',
    method: 'put',
    params:{
      status:status,
      id:id
    }
  }).then((res)=>{

    if (res.data.data === 1){
      ElMessage.success("已通过")
    }else {
      ElMessage.info("已驳回")
    }
    getMyActivity()
  })
}

//团长删除学生的活动申请
const DeleteStudent = (id) => {
  ElMessageBox.confirm(
      '确认删除该名学生的申请?',
      '温馨提示',
      {
        confirmButtonText:'确认',
        cancelButtonText:'取消',
        type:'warning'
      }
  )
      .then(()=>{
        request9191({
          url:'/ClubActReg',
          method:'delete',
          params:{
            id:id
          }
        }).then(() =>{
          ElMessage.success('删除成功')
          getMyActivity()
        })
      }).catch(() =>{
    ElMessage({
      type:'info',
      message:'已取消'
    })
  })
}
getMyActivity()
</script>

<template>
  <el-card>
    <el-table :data="MyActivity" style="width: 100% " border="border">
      <el-table-column prop="id" label="ID" width="140px"/>
      <el-table-column prop="sname" label="姓名" width="140px"/>
      <el-table-column prop="sclass" label="班级" width="140px"/>
      <el-table-column prop="snumber" label="学号" width="150px"/>
      <el-table-column prop="actName" label="活动名称" width="100px"/>
      <el-table-column prop="actClub" label="举办社团" width="100px"/>
      <el-table-column label="状态" width="100px">
        <template #default="scope">
          <el-tag v-if="scope.row.status === 0" type="warning">待审核</el-tag>
          <el-tag v-else-if="scope.row.status === 1" type="success">已通过</el-tag>
          <el-tag v-else type="danger">已驳回</el-tag>
        </template>
      </el-table-column>

      <el-table-column  label="审核" width="150px">
        <template #default="scope">
          <el-button size="small" type="success" @click="updateModStatus('1',scope.row.id)">通过</el-button>
          <el-button size="small" type="danger" @click="updateModStatus('2' , scope.row.id)">驳回</el-button>
        </template>
      </el-table-column>

      <el-table-column label="操作" width="150px">
        <template #default="scope">
          <el-button size="default" type="danger" @click="DeleteStudent(scope.row.id)">
            <el-icon><Delete /></el-icon>
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-card>
</template>

<style scoped>

</style>